<?php

/**
 * 区域下拉
 * @return string
 */
function areaOption($area,$id = '',$type = false){
    $str = '';
    foreach ($area as $v) {
        if ($id == $v['id']) {
            $str .= '<option level="1" value="'.$v['id'].'" selected>'.$v['areaname'].'</option>';
        } else {
            $str .= '<option level="1" value="'.$v['id'].'">'.$v['areaname'].'</option>';
        }
        if ($v['child']) {
            foreach ($v['child'] as $vv) {
                if ($id == $vv['id']) {
                    $str .= '<option level="2" value="'.$vv['id'].'" selected>|-- '.$vv['areaname'].'</option>';
                } else {
                    $str .= '<option level="2" value="'.$vv['id'].'">|-- '.$vv['areaname'].'</option>';
                }
                if ($vv['child']) {
                    foreach ($vv['child'] as $vvv) {
                        if ($id == $vvv['id']) {
                            $str .= '<option level="3" value="'.$vvv['id'].'" selected>|---- '.$vvv['areaname'].'</option>';
                        } else {
                            $str .= '<option level="3" value="'.$vvv['id'].'">|---- '.$vvv['areaname'].'</option>';
                        }
                        if ($vvv['child']) {
                            foreach ($vvv['child'] as $vvvv) {
                                if ($id == $vvvv['id']) {
                                    $str .= '<option level="4" value="'.$vvvv['id'].'" selected>|------ '.$vvvv['areaname'].'</option>';
                                } else {
                                    $str .= '<option level="4" value="'.$vvvv['id'].'">|------ '.$vvvv['areaname'].'</option>';
                                }
                                if ($vvvv['child']) {
                                    foreach ($vvvv['child'] as $vvvvv) {
                                        if ($type) {
                                            $str .= '<option level="5" value="'.$vvvvv['id'].'" disabled>|-------- '.$vvvvv['areaname'].'</option>';
                                        }elseif ($id == $vvvvv['id']) {
                                            $str .= '<option level="5" value="'.$vvvvv['id'].'" selected>|-------- '.$vvvvv['areaname'].'</option>';
                                        }else {
                                            $str .= '<option level="5" value="'.$vvvvv['id'].'">|-------- '.$vvvvv['areaname'].'</option>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $str;
}
